home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / C for beginners.adf / source / read_dir.c < prev    next >
C/C++ Source or Header  |  1978-01-17  |  1KB  |  64 lines

  1. /* read_dir.c 25.7             */
  2. /* From Amiga C for Beginners */
  3. /* by Abacus                  */
  4.  
  5. #include <libraries/dos.h>
  6.  
  7. struct FileInfoBlock fi;
  8.  
  9. main(argc, argv)
  10. int argc;
  11. char *argv[];
  12. {
  13.    long lock;
  14.    int error;
  15.    char filepath[100];
  16.  
  17.    if(argc == 2)   /* parameter present ? */
  18.       strcpy(filepath, argv[1]);
  19.    else
  20.       strcpy(filepath, "sys:");
  21.  
  22.    lock = Lock(filepath, ACCESS_READ);
  23.    printf("Lock value %d\n", lock);
  24.    if(!lock)
  25.       {
  26.          printf("No Lock! ERROR!\n");
  27.          exit(FALSE);
  28.       }
  29.  
  30.    if(Examine(lock, &fi))  /* First call successful? */
  31.       do
  32.         output(); /* Return value not of interest now */
  33.       while(ExNext(lock, &fi)); /* until error occurs */
  34.  
  35.    error = IoErr();   /* What Error? */
  36.    if(error != ERROR_NO_MORE_ENTRIES) /* "real" Error! */
  37.       printf("Error %d occurred!\n", error);
  38.  
  39.    exit(TRUE);
  40. }
  41.  
  42. output()
  43. {
  44.    if(!*fi.fib_FileName) /* strlen = 0 */
  45.      {
  46.        printf("Empty!\n");
  47.         /* for example Root-directory of RAM Disk */
  48.        return(0); /* That's directory without name */
  49.      }
  50.    if(fi.fib_DirEntryType > 0)
  51.      printf("Directory name");
  52.    else
  53.      printf("Filename      ");
  54.  
  55.    printf(": >%20s< RWXD %lx bytes: %-6ld Blocks %-4ld\n",
  56.           fi.fib_FileName, fi.fib_Protection,
  57.           fi.fib_Size, fi.fib_NumBlocks);
  58.  
  59.    if(*fi.fib_Comment) /* If comment present, output! */
  60.       printf("Comment: >%s<\n", fi.fib_Comment);
  61.    return(fi.fib_DirEntryType > 0); /*Return File Type */
  62. }
  63.  
  64.